package com.coral.login.module.maya.android;

import java.util.Comparator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;

import org.apache.commons.lang3.StringUtils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

public class MayaConfig {
	
	public static String requestUrl = "http://jhsdk.maya88.cn/user/verify";
	//public static String requestAuthUrl = "http://jh.9wcloud.com/user/gettoken";
	//public static String requestAuthUrl =  "https://kzjh.flygamebox.com/user/verify";
	public static String paykey = "3971f1fc74ecd608177cfd2ef07e40b5";
	
//	/**
//	 * map中的数据组装后生成md5 签名
//	 * 
//	 * @style key1=value1&key2=value2
//	 * @param map
//	 * @return
//	 */
//	public static String getLocalSignByMap(Map<String, String> map, String... extras) {
//		StringBuilder url = new StringBuilder();
//		for (Map.Entry<String, String> entry : map.entrySet()) {
//			url.append(entry.getKey()).append("=").append(entry.getValue()).append("&");
//		}
//		for (String extra : extras) {
//			url.append(extra).append("&");
//		}
//		url.deleteCharAt(url.length() - 1);
//		// md5加密
//		String mySign = MD5.digest(url.toString(), true);
//		return mySign;
//	}
	
	/**
	 * 把对象转成Map
	 * @param obj
	 * @param extract
	 *            除去需要解析的字段
	 * @return
	 * @return Map<String,String>
	 * @date 2018年9月25日下午4:39:10
	 */
	public static Map<String, String> objToTreeMap(Object obj, String... extract) {
		Map<String, String> sortMap = new TreeMap<String, String>(new Comparator<String>() {
			@Override
			public int compare(String str1, String str2) {
				return str1.compareTo(str2);
			}
		});
		JSONObject jsonObject = (JSONObject) JSON.toJSON(obj);
		Set<Entry<String, Object>> entrySet = jsonObject.entrySet();
		for (Entry<String, Object> entry : entrySet) {
			String key = entry.getKey();
			String value = String.valueOf(entry.getValue());
			if (StringUtils.containsAny(key, extract)) {
				continue;
			}
			sortMap.put(key, value);
		}
		return sortMap;
	}

	
}
